package com.soilflow.system.service.impl;
import com.soilflow.common.utils.file.FileUploadUtils;
import com.soilflow.common.utils.qinniu.QiNiuUtil;
import com.soilflow.system.service.ISysFileService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;


@Primary
@Service
public class QiNiuSysFileServiceImpl implements ISysFileService {

    @Override
    public String uploadFile(MultipartFile file) throws Exception {
            //判断文件是否为空
            if (file.isEmpty()) {
                return "error";
            }
            //获取UUID+date文件名
            String fileName = QiNiuUtil.getUUIDFileNameNow(file.getOriginalFilename());
            //获取文件上传七牛云后的url
            String fileUrl = QiNiuUtil.saveFile(file, fileName);
            return fileUrl;
    }


    @Override
    public String uploadFile(File file) throws Exception {
        return uploadFile(FileUploadUtils.getMultipartFile(file));
    }

}